<div class="row">
	<div class="col-xs-12">
		<div class="box">
			<div class="box-header">
				<h3 class="box-title">日志管理</h3>
				<div class="box-tools">
					<div class="input-group input-group-sm" style="width: 350px;">
						<input type="text" name="table_search" id="searchNameId"
							class="form-control pull-right" placeholder="用户名">

						<div class="input-group-btn">
							<button type="button" class="btn btn-default btn-search">
                                <i class="fa fa-search"></i>
							</button>
							<button type="button" class="btn btn-default btn-delete">删除</button>
						</div>
					</div>
				</div>
			</div>
			<!-- /.box-header -->
			<div class="box-body table-responsive no-padding">
				<table class="table table-hover">
					<thead>
						<tr>
						    <th><input type="checkbox" id="checkAll">全选</th>
							<th>用户名</th>
							<th>操作</th>
							<th>请求方法</th>
							<th>请求参数</th>
							<th>IP</th>
							<th>执行时长</th>
						</tr>
					</thead>
					<tbody id="tbodyId">
					    <tr>
					       <td colspan="7">数据正在加载中...</td>
					    </tr>
					</tbody>
				</table>
			</div>
			<div id="pageId" class="box-footer clearfix" dm="100">
			  
			</div>
			<!-- /.box-body -->
		</div>
		<!-- /.box -->
	</div>
</div>
<script type="text/javascript">
	$(function () {
		$("#pageId").load("doPageUI", function () {
			doGetObjects();
		});
		//注册删除按钮
		$(".input-group-btn").on("click", ".btn-delete", doDeleteObjects)
	});
	//删除操作
	function doDeleteObjects() {
		debugger;
		var ids = doGetCheckedIds();
		if (ids.length == 0) {
			alert("至少选择一个");
			return;
		}
		var url = "log/doDeleteObjects";
		var params = {"ids": ids.toString()}
		console.log(params);
		console.log("ids是" + ids);
		console.log("ids.toString是" + ids.toString());
		$.post(url, params, function (result) {
			if (result.state == 1) {
				alert(result.message);
				doGetObjects();
				doRefreshAfterDeleteOK();
			} else {
				alert(result.message);
			}
		});
	}
	//获取勾选的数据的id
	function doGetCheckedIds() {
		var array = [];
		$("#tbodyId input[type=checkbox]")
				.each(function () {
					if ($(this).prop("checked")) {
						array.push($(this).val());
					}
				});
		return array;
	}
	//全选按钮的功能
	function doChangeTbodyCheckBoxState() {
		var flag = $(this).prop("checked");
		$("#tbodyId input[type='checkbox']").prop("checked", flag);
	}
	//删除成功后刷新功能
	function doRefreshAfterDeleteOK(){
		var pageCount=$("#pageId").data("pageCount");
		var pageCurrent=$("#pageId").data("pageCurrent");
		var checked=$("#checkAll").prop("checked");
		if(pageCurrent==pageCount&&checked&&pageCurrent>1){
			pageCurrent--;
			$("#pageId").data("pageCurrent",pageCurrent);
		}
		doGetObjects();
	}

	//获取日志数据
	function doGetObjects() {
		var url = "log/doFindPageObjects";

		var pageCurrent = $("#pageId").data("pageCurrent");
		if(!pageCurrent) pageCurrent = 1;

		var params = {"pageCurrent": pageCurrent};
		$.getJSON(url, params, function (result) {
			doHandleQueryResponseResult(result);
		});
	}
	function doHandleQueryResponseResult (result) {
		if (result.state == 1) {
			doSetTableBodyRows(result.data.records);
			doSetPagination(result.data);
		} else {
			alert(result.message);
		}
	}

	function doSetTableBodyRows(records) {
		var tBody = $("#tbodyId");
		tBody.empty();
		for (var i in records) {
			var tr = $("<tr></tr>");
			var tds = doCreateTds(records[i]);
			tr.append(tds);
			tBody.append(tr);
		}
	}

	function doCreateTds(data) {
		var tds = "<td><input type='checkbox' class='cBox' name='cItem' value='"+data.id+"'></td>"+
				"<td>"+data.username+"</td>"+
				"<td>"+data.operation+"</td>"+
				"<td>"+data.method+"</td>"+
				"<td>"+data.params+"</td>"+
				"<td>"+data.ip+"</td>"+
				"<td>"+data.time+"</td>";
		return tds;
	}

	function doSetPagination(page) {
		//初始化
		$(".rowCount").html("总记录数（" + page.rowCount + ")");
		$(".pageCount").html("总记录数（" + page.pageCount + ")");
		$(".pageCurrent").html("总记录数（" + page.pageCurrent + ")");
		//绑定(为后续对此数据的使用提供服务)
		$("#pageId").data("pageCurrent", page.pageCurrent);
		$("#pageId").data("pageCount", page.pageCount);
	}
</script>






